using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.UI;

namespace MaterialUI
{
	[AddComponentMenu("MaterialUI/Dropdown", 100)]
	public class MaterialDropdown : UIBehaviour, IOptionDataListContainer
	{
		public enum VerticalPivotType
		{
			BelowBase,
			Top,
			FirstItem,
			Center,
			LastItem,
			Bottom,
			AboveBase
		}

		public enum HorizontalPivotType
		{
			Left,
			Center,
			Right
		}

		public enum ExpandStartType
		{
			ExpandFromNothing,
			ExpandFromBaseTransformWidth,
			ExpandFromBaseTransformHeight,
			ExpandFromBaseTransformSize
		}

		[Serializable]
		public class DropdownListItem
		{
			public RectTransform m_RectTransform;

			public CanvasGroup m_CanvasGroup;

			public Text m_Text;

			public Graphic m_Image;

			public RectTransform rectTransform
			{
				get
				{
					return m_RectTransform;
				}
				set
				{
					m_RectTransform = value;
				}
			}

			public CanvasGroup canvasGroup
			{
				get
				{
					return m_CanvasGroup;
				}
				set
				{
					m_CanvasGroup = value;
				}
			}

			public Text text
			{
				get
				{
					return m_Text;
				}
				set
				{
					m_Text = value;
				}
			}

			public Graphic image
			{
				get
				{
					return m_Image;
				}
				set
				{
					m_Image = value;
				}
			}
		}

		[Serializable]
		public class MaterialDropdownEvent : UnityEvent<int>
		{
		}

		[SerializeField]
		private VerticalPivotType m_VerticalPivotType = VerticalPivotType.FirstItem;

		[SerializeField]
		private HorizontalPivotType m_HorizontalPivotType;

		[SerializeField]
		private ExpandStartType m_ExpandStartType = ExpandStartType.ExpandFromBaseTransformSize;

		[SerializeField]
		private float m_IgnoreInputAfterShowTimer;

		[SerializeField]
		private float m_MaxHeight = 200f;

		[SerializeField]
		private bool m_CapitalizeButtonText = true;

		[SerializeField]
		private bool m_HighlightCurrentlySelected = true;

		[SerializeField]
		private bool m_UpdateHeader = true;

		[SerializeField]
		private float m_AnimationDuration = 0.3f;

		[SerializeField]
		private float m_MinDistanceFromEdge = 16f;

		[SerializeField]
		private Color m_PanelColor = Color.white;

		[SerializeField]
		private RippleData m_ItemRippleData;

		[SerializeField]
		private Color m_ItemTextColor = MaterialColor.textDark;

		[SerializeField]
		private Color m_ItemIconColor = MaterialColor.iconDark;

		[SerializeField]
		private RectTransform m_BaseTransform;

		[SerializeField]
		private Selectable m_BaseSelectable;

		[SerializeField]
		private Text m_ButtonTextContent;

		[SerializeField]
		private Graphic m_ButtonImageContent;

		[SerializeField]
		private int m_CurrentlySelected;

		[SerializeField]
		private OptionDataList m_OptionDataList;

		[SerializeField]
		private MaterialDropdownEvent m_OnItemSelected = new MaterialDropdownEvent();

		private List<DropdownListItem> m_ListItems = new List<DropdownListItem>();

		private MaterialUIScaler m_Scaler;

		private RectTransform m_DropdownPanel;

		private RectTransform m_PanelLayer;

		private CanvasGroup m_DropdownCanvasGroup;

		private Canvas m_DropdownCanvas;

		private CanvasGroup m_ShadowCanvasGroup;

		private DropdownListItem m_ListItemTemplate;

		private RectTransform m_CancelPanel;

		private Vector2 m_ExpandedSize;

		private Vector3 m_ExpandedPosition;

		private float m_FullHeight;

		private bool m_IsExapanded;

		private float m_TempMaxHeight;

		private float m_ScrollPosOffset;

		private float m_TimeShown;

		private GameObject m_DropdownCanvasGameObject;

		private List<int> m_AutoTweeners;

		private List<int> m_ListItemAutoTweeners = new List<int>();

		public VerticalPivotType verticalPivotType
		{
			get
			{
				return m_VerticalPivotType;
			}
			set
			{
				m_VerticalPivotType = value;
			}
		}

		public HorizontalPivotType horizontalPivotType
		{
			get
			{
				return m_HorizontalPivotType;
			}
			set
			{
				m_HorizontalPivotType = value;
			}
		}

		public ExpandStartType expandStartType
		{
			get
			{
				return m_ExpandStartType;
			}
			set
			{
				m_ExpandStartType = value;
			}
		}

		public float ignoreInputAfterShowTimer
		{
			get
			{
				return m_IgnoreInputAfterShowTimer;
			}
			set
			{
				m_IgnoreInputAfterShowTimer = value;
			}
		}

		public float maxHeight
		{
			get
			{
				return m_MaxHeight;
			}
			set
			{
				m_MaxHeight = value;
			}
		}

		public bool capitalizeButtonText
		{
			get
			{
				return m_CapitalizeButtonText;
			}
			set
			{
				m_CapitalizeButtonText = value;
			}
		}

		public bool highlightCurrentlySelected
		{
			get
			{
				return m_HighlightCurrentlySelected;
			}
			set
			{
				m_HighlightCurrentlySelected = value;
			}
		}

		public bool updateHeader
		{
			get
			{
				return m_UpdateHeader;
			}
			set
			{
				m_UpdateHeader = value;
			}
		}

		public float animationDuration
		{
			get
			{
				return m_AnimationDuration;
			}
			set
			{
				m_AnimationDuration = value;
			}
		}

		public float minDistanceFromEdge
		{
			get
			{
				return m_MinDistanceFromEdge;
			}
			set
			{
				m_MinDistanceFromEdge = value;
			}
		}

		public Color panelColor
		{
			get
			{
				return m_PanelColor;
			}
			set
			{
				m_PanelColor = value;
			}
		}

		public RippleData itemRippleData
		{
			get
			{
				return m_ItemRippleData;
			}
			set
			{
				m_ItemRippleData = value;
			}
		}

		public Color itemTextColor
		{
			get
			{
				return m_ItemTextColor;
			}
			set
			{
				m_ItemTextColor = value;
			}
		}

		public Color itemIconColor
		{
			get
			{
				return m_ItemIconColor;
			}
			set
			{
				m_ItemIconColor = value;
			}
		}

		public RectTransform baseTransform
		{
			get
			{
				return m_BaseTransform;
			}
			set
			{
				m_BaseTransform = value;
			}
		}

		public Selectable baseSelectable
		{
			get
			{
				return m_BaseSelectable;
			}
			set
			{
				m_BaseSelectable = value;
			}
		}

		public Text buttonTextContent
		{
			get
			{
				return m_ButtonTextContent;
			}
			set
			{
				m_ButtonTextContent = value;
			}
		}

		public Graphic buttonImageContent
		{
			get
			{
				return m_ButtonImageContent;
			}
			set
			{
				m_ButtonImageContent = value;
			}
		}

		public int currentlySelected
		{
			get
			{
				return m_CurrentlySelected;
			}
			set
			{
				m_CurrentlySelected = Mathf.Clamp(value, -1, m_OptionDataList.options.Count - 1);
				if (m_CurrentlySelected < 0)
				{
					return;
				}
				if (m_ButtonImageContent != null)
				{
					m_ButtonImageContent.SetImage(m_OptionDataList.options[m_CurrentlySelected].imageData);
				}
				if (m_ButtonTextContent != null)
				{
					string text = m_OptionDataList.options[m_CurrentlySelected].text;
					if (m_CapitalizeButtonText)
					{
						text = text.ToUpper();
					}
					m_ButtonTextContent.text = text;
				}
			}
		}

		public OptionDataList optionDataList
		{
			get
			{
				return m_OptionDataList;
			}
			set
			{
				m_OptionDataList = value;
			}
		}

		public MaterialDropdownEvent onItemSelected
		{
			get
			{
				return m_OnItemSelected;
			}
			set
			{
				m_OnItemSelected = value;
			}
		}

		public List<DropdownListItem> listItems
		{
			get
			{
				return m_ListItems;
			}
			set
			{
				m_ListItems = value;
			}
		}

		private MaterialUIScaler scaler
		{
			get
			{
				if (m_Scaler == null)
				{
					m_Scaler = MaterialUIScaler.GetParentScaler(base.transform);
				}
				return m_Scaler;
			}
		}

		public void AddData(OptionData data)
		{
			m_OptionDataList.options.Add(data);
		}

		public void AddData(OptionData[] data)
		{
			for (int i = 0; i < data.Length; i++)
			{
				AddData(data[i]);
			}
		}

		public void RemoveData(OptionData data)
		{
			m_OptionDataList.options.Remove(data);
			m_CurrentlySelected = Mathf.Clamp(m_CurrentlySelected, 0, m_OptionDataList.options.Count - 1);
		}

		public void RemoveData(OptionData[] data)
		{
			for (int i = 0; i < data.Length; i++)
			{
				RemoveData(data[i]);
			}
		}

		public void ClearData()
		{
			m_OptionDataList.options.Clear();
			m_CurrentlySelected = Mathf.Clamp(m_CurrentlySelected, 0, m_OptionDataList.options.Count - 1);
		}

		protected override void Start()
		{
			Canvas[] array = UnityEngine.Object.FindObjectsOfType<Canvas>();
			for (int i = 0; i < array.Length; i++)
			{
				if (array[i].name == "Dropdown Canvas")
				{
					m_DropdownCanvasGameObject = array[i].gameObject;
				}
			}
			if (m_DropdownCanvasGameObject == null)
			{
				m_DropdownCanvasGameObject = new GameObject("Dropdown Canvas");
			}
			m_DropdownCanvas = m_BaseTransform.root.GetComponent<Canvas>().Copy(m_DropdownCanvasGameObject);
		}

		public void Show()
		{
			m_BaseTransform.root.GetComponent<Canvas>().CopySettingsToOtherCanvas(m_DropdownCanvas);
			m_DropdownCanvas.pixelPerfect = true;
			m_DropdownCanvas.sortingOrder = 30000;
			m_DropdownPanel = PrefabManager.InstantiateGameObject("Menus/Dropdown Panel", m_DropdownCanvas.transform).GetComponent<RectTransform>();
			m_PanelLayer = m_DropdownPanel.GetChildByName<RectTransform>("PanelLayer");
			m_DropdownCanvasGroup = m_DropdownPanel.GetComponent<CanvasGroup>();
			m_ShadowCanvasGroup = m_DropdownPanel.GetChildByName<CanvasGroup>("Shadow");
			m_CancelPanel = m_DropdownPanel.GetChildByName<RectTransform>("Cancel Panel");
			m_CancelPanel.sizeDelta = scaler.targetCanvas.pixelRect.size * 2f;
			DropdownTrigger childByName = m_DropdownPanel.gameObject.GetChildByName<DropdownTrigger>("Cancel Panel");
			childByName.index = -1;
			childByName.dropdown = this;
			m_DropdownPanel.gameObject.GetChildByName<Image>("ScrollRect").color = m_PanelColor;
			m_ListItemTemplate = new DropdownListItem();
			m_ListItemTemplate.rectTransform = m_DropdownPanel.GetChildByName<RectTransform>("Item");
			m_ListItemTemplate.canvasGroup = m_ListItemTemplate.rectTransform.GetComponent<CanvasGroup>();
			m_ListItemTemplate.text = m_ListItemTemplate.rectTransform.GetChildByName<Text>("Text");
			if (m_OptionDataList.imageType == ImageDataType.Sprite)
			{
				m_ListItemTemplate.image = m_ListItemTemplate.rectTransform.GetChildByName<Image>("Icon");
				UnityEngine.Object.Destroy(m_ListItemTemplate.rectTransform.GetChildByName<VectorImage>("Icon").gameObject);
			}
			else
			{
				m_ListItemTemplate.image = m_ListItemTemplate.rectTransform.GetChildByName<VectorImage>("Icon");
				UnityEngine.Object.Destroy(m_ListItemTemplate.rectTransform.GetChildByName<Image>("Icon").gameObject);
			}
			m_ListItems = new List<DropdownListItem>();
			for (int i = 0; i < m_OptionDataList.options.Count; i++)
			{
				m_ListItems.Add(CreateItem(m_OptionDataList.options[i], i));
			}
			for (int j = 0; j < m_ListItems.Count; j++)
			{
				Selectable component = m_ListItems[j].rectTransform.GetComponent<Selectable>();
				Navigation navigation = default(Navigation);
				navigation.mode = Navigation.Mode.Explicit;
				if (j > 0)
				{
					navigation.selectOnUp = m_ListItems[j - 1].rectTransform.GetComponent<Selectable>();
				}
				if (j < m_ListItems.Count - 1)
				{
					navigation.selectOnDown = m_ListItems[j + 1].rectTransform.GetComponent<Selectable>();
				}
				component.navigation = navigation;
			}
			if (m_BaseSelectable != null && m_ListItems.Count > 0)
			{
				Navigation defaultNavigation = Navigation.defaultNavigation;
				defaultNavigation.selectOnDown = m_ListItems[0].rectTransform.GetComponent<Selectable>();
				m_BaseSelectable.navigation = defaultNavigation;
			}
			float a = CalculateMaxItemWidth();
			float width = m_BaseTransform.rect.width;
			m_FullHeight = (float)m_OptionDataList.options.Count * LayoutUtility.GetPreferredHeight(m_ListItemTemplate.rectTransform) + 16f;
			m_ExpandedSize = new Vector2(Mathf.Max(a, width), m_FullHeight);
			m_TempMaxHeight = m_MaxHeight;
			if (m_TempMaxHeight == 0f)
			{
				m_TempMaxHeight = MaterialUIScaler.GetParentScaler(m_DropdownPanel).targetCanvas.GetComponent<RectTransform>().rect.height - 32f;
			}
			if (m_ExpandedSize.y > m_TempMaxHeight)
			{
				m_ExpandedSize.y = m_TempMaxHeight;
			}
			else
			{
				m_DropdownPanel.GetChildByName<Image>("Handle").gameObject.SetActive(value: false);
			}
			UnityEngine.Object.Destroy(m_ListItemTemplate.rectTransform.gameObject);
			m_DropdownPanel.position = m_BaseTransform.GetPositionRegardlessOfPivot();
			if (m_ExpandStartType == ExpandStartType.ExpandFromBaseTransformWidth)
			{
				if (m_VerticalPivotType == VerticalPivotType.BelowBase)
				{
					RectTransform dropdownPanel = m_DropdownPanel;
					Vector3 position = m_DropdownPanel.position;
					float x = position.x;
					Vector3 position2 = m_DropdownPanel.position;
					float y = position2.y;
					Vector2 properSize = m_BaseTransform.GetProperSize();
					float y2 = y - properSize.y / 2f;
					Vector3 position3 = m_DropdownPanel.position;
					dropdownPanel.position = new Vector3(x, y2, position3.z);
				}
				else if (m_VerticalPivotType == VerticalPivotType.AboveBase)
				{
					RectTransform dropdownPanel2 = m_DropdownPanel;
					Vector3 position4 = m_DropdownPanel.position;
					float x2 = position4.x;
					Vector3 position5 = m_DropdownPanel.position;
					float y3 = position5.y;
					Vector2 properSize2 = m_BaseTransform.GetProperSize();
					float y4 = y3 + properSize2.y / 2f;
					Vector3 position6 = m_DropdownPanel.position;
					dropdownPanel2.position = new Vector3(x2, y4, position6.z);
				}
			}
			m_ExpandedPosition = CalculatedPosition();
			ref Vector3 expandedPosition = ref m_ExpandedPosition;
			Vector3 position7 = m_BaseTransform.position;
			expandedPosition.z = position7.z;
			m_DropdownCanvasGroup.alpha = 0f;
			m_ShadowCanvasGroup.alpha = 0f;
			if (m_ExpandStartType == ExpandStartType.ExpandFromBaseTransformWidth)
			{
				RectTransform dropdownPanel3 = m_DropdownPanel;
				Vector2 size = m_BaseTransform.rect.size;
				dropdownPanel3.sizeDelta = new Vector2(size.x, 0f);
			}
			else if (m_ExpandStartType == ExpandStartType.ExpandFromBaseTransformHeight)
			{
				RectTransform dropdownPanel4 = m_DropdownPanel;
				Vector2 size2 = m_BaseTransform.rect.size;
				dropdownPanel4.sizeDelta = new Vector2(0f, size2.y);
			}
			else if (m_ExpandStartType == ExpandStartType.ExpandFromBaseTransformSize)
			{
				m_DropdownPanel.sizeDelta = m_BaseTransform.rect.size;
			}
			else
			{
				m_DropdownPanel.sizeDelta = Vector2.zero;
			}
			m_DropdownPanel.gameObject.SetActive(value: true);
			for (int k = 0; k < m_ListItemAutoTweeners.Count; k++)
			{
				TweenManager.EndTween(m_ListItemAutoTweeners[k]);
			}
			m_AutoTweeners = new List<int>();
			m_ListItemAutoTweeners = new List<int>();
			m_AutoTweeners.Add(TweenManager.TweenFloat(delegate(float f)
			{
				m_DropdownCanvasGroup.alpha = f;
			}, m_DropdownCanvasGroup.alpha, 1f, m_AnimationDuration * 0.66f, 0f, null, scaledTime: false, Tween.TweenType.Linear));
			m_AutoTweeners.Add(TweenManager.TweenFloat(delegate(float f)
			{
				m_ShadowCanvasGroup.alpha = f;
			}, m_ShadowCanvasGroup.alpha, 1f, m_AnimationDuration * 0.66f, 0f, null, scaledTime: false, Tween.TweenType.Linear));
			m_AutoTweeners.Add(TweenManager.TweenVector2(delegate(Vector2 vector2)
			{
				m_DropdownPanel.sizeDelta = vector2;
			}, m_DropdownPanel.sizeDelta, m_ExpandedSize, m_AnimationDuration, m_AnimationDuration / 3f, null, scaledTime: false, Tween.TweenType.EaseInOutQuint));
			m_AutoTweeners.Add(TweenManager.TweenVector3(delegate(Vector3 vector3)
			{
				m_DropdownPanel.position = vector3;
			}, m_DropdownPanel.position, m_ExpandedPosition, m_AnimationDuration, m_AnimationDuration / 3f, delegate
			{
				if (m_BaseSelectable != null && m_IsExapanded)
				{
					m_BaseSelectable.interactable = false;
				}
				Vector2 anchoredPosition = m_PanelLayer.anchoredPosition;
				anchoredPosition.x = Mathf.RoundToInt(anchoredPosition.x);
				anchoredPosition.y = Mathf.RoundToInt(anchoredPosition.y);
				m_PanelLayer.anchoredPosition = anchoredPosition;
			}, scaledTime: false, Tween.TweenType.EaseInOutQuint));
			for (int l = 0; l < m_ListItems.Count; l++)
			{
				int num = l;
				CanvasGroup canvasGroup = m_ListItems[l].canvasGroup;
				m_ListItemAutoTweeners.Add(TweenManager.TweenFloat(delegate(float f)
				{
					canvasGroup.alpha = f;
				}, canvasGroup.alpha, 1f, m_AnimationDuration * 1.66f, (float)num * (m_AnimationDuration / 6f) + m_AnimationDuration - m_ScrollPosOffset / 800f, null, scaledTime: false, Tween.TweenType.Linear));
			}
			if (m_FullHeight > m_TempMaxHeight)
			{
				m_DropdownPanel.GetChildByName<ScrollRect>("ScrollRect").gameObject.AddComponent<RectMask2D>();
			}
			m_IsExapanded = true;
			m_TimeShown = Time.unscaledTime;
		}

		public void Hide()
		{
			for (int i = 0; i < m_ListItemAutoTweeners.Count; i++)
			{
				TweenManager.EndTween(m_ListItemAutoTweeners[i]);
			}
			m_IsExapanded = false;
			if (m_BaseSelectable != null)
			{
				m_BaseSelectable.interactable = true;
			}
			for (int j = 0; j < m_ListItems.Count; j++)
			{
				int num = j;
				CanvasGroup canvasGroup = m_ListItems[j].canvasGroup;
				TweenManager.TweenFloat(delegate(float f)
				{
					canvasGroup.alpha = f;
				}, canvasGroup.alpha, 0f, m_AnimationDuration * 0.66f, (float)(m_ListItems.Count - num) * (m_AnimationDuration / 6f), null, scaledTime: false, Tween.TweenType.Linear);
			}
			m_AutoTweeners.Add(TweenManager.TweenFloat(delegate(float f)
			{
				m_DropdownCanvasGroup.alpha = f;
			}, m_DropdownCanvasGroup.alpha, 0f, m_AnimationDuration * 0.66f, m_AnimationDuration, null, scaledTime: false, Tween.TweenType.Linear));
			TweenManager.TweenFloat(delegate(float f)
			{
				m_ShadowCanvasGroup.alpha = f;
			}, m_ShadowCanvasGroup.alpha, 0f, m_AnimationDuration * 0.66f, m_AnimationDuration, delegate
			{
				for (int k = 0; k < m_AutoTweeners.Count; k++)
				{
					TweenManager.EndTween(m_AutoTweeners[k]);
				}
				UnityEngine.Object.Destroy(m_DropdownPanel.gameObject);
			}, scaledTime: false, Tween.TweenType.Linear);
		}

		public void Select(int selectedItem, bool submitted = false)
		{
			if (Time.unscaledTime - m_TimeShown < m_IgnoreInputAfterShowTimer || !m_IsExapanded)
			{
				return;
			}
			if (selectedItem >= 0)
			{
				if (m_ButtonImageContent != null && m_UpdateHeader)
				{
					m_ButtonImageContent.SetImage(m_OptionDataList.options[selectedItem].imageData);
				}
				if (m_ButtonTextContent != null && m_UpdateHeader)
				{
					string text = m_OptionDataList.options[selectedItem].text;
					if (m_CapitalizeButtonText)
					{
						text = text.ToUpper();
					}
					m_ButtonTextContent.text = text;
				}
				m_CurrentlySelected = selectedItem;
			}
			Hide();
			if (submitted && m_BaseSelectable != null)
			{
				EventSystem.current.SetSelectedGameObject(m_BaseSelectable.gameObject);
			}
			if (m_OnItemSelected != null)
			{
				m_OnItemSelected.Invoke(selectedItem);
			}
			if (selectedItem >= 0 && selectedItem < m_OptionDataList.options.Count)
			{
				m_OptionDataList.options[selectedItem].onOptionSelected.InvokeIfNotNull();
			}
		}

		private Vector3 CalculatedPosition()
		{
			Vector3 positionRegardlessOfPivot = m_BaseTransform.GetPositionRegardlessOfPivot();
			Vector2 properSize = m_ListItemTemplate.rectTransform.GetProperSize();
			float y = properSize.y;
			float min = 0f;
			float max = Mathf.Clamp(m_FullHeight - m_TempMaxHeight, 0f, float.MaxValue);
			int num = (m_VerticalPivotType < VerticalPivotType.Center) ? 1 : (-1);
			if (m_VerticalPivotType == VerticalPivotType.BelowBase || m_VerticalPivotType == VerticalPivotType.AboveBase)
			{
				Vector2 properSize2 = m_BaseTransform.GetProperSize();
				float y2 = properSize2.y;
				positionRegardlessOfPivot.y -= m_ExpandedSize.y * scaler.scaler.scaleFactor / 2f * (float)num;
				positionRegardlessOfPivot.y -= y2 * scaler.scaler.scaleFactor / 2f * (float)num;
			}
			else if (m_VerticalPivotType == VerticalPivotType.Top || m_VerticalPivotType == VerticalPivotType.Bottom)
			{
				positionRegardlessOfPivot.y -= m_ExpandedSize.y * scaler.scaler.scaleFactor / 2f * (float)num;
				positionRegardlessOfPivot.y += y * scaler.scaler.scaleFactor / 2f * (float)num;
				positionRegardlessOfPivot.y -= 3f * scaler.scaler.scaleFactor * (float)num;
			}
			else if (m_VerticalPivotType == VerticalPivotType.FirstItem || m_VerticalPivotType == VerticalPivotType.LastItem)
			{
				positionRegardlessOfPivot.y -= m_ExpandedSize.y * scaler.scaler.scaleFactor / 2f * (float)num;
				positionRegardlessOfPivot.y += y * scaler.scaler.scaleFactor / 2f * (float)num;
				positionRegardlessOfPivot.y += 8f * scaler.scaler.scaleFactor * (float)num;
			}
			if (m_HighlightCurrentlySelected)
			{
				Vector2 anchoredPosition = m_PanelLayer.anchoredPosition;
				anchoredPosition.y += y * (float)Mathf.Clamp(m_CurrentlySelected, 0, int.MaxValue);
				if (m_VerticalPivotType == VerticalPivotType.Center)
				{
					anchoredPosition.y -= m_ExpandedSize.y / 2f;
					anchoredPosition.y += y / 2f;
					anchoredPosition.y += 8f;
				}
				else if (m_VerticalPivotType == VerticalPivotType.LastItem)
				{
					anchoredPosition.y -= m_ExpandedSize.y;
					anchoredPosition.y += y;
					anchoredPosition.y += 16f;
				}
				anchoredPosition.y = Mathf.Clamp(anchoredPosition.y, min, max);
				m_PanelLayer.anchoredPosition = anchoredPosition;
				m_ScrollPosOffset = anchoredPosition.y;
			}
			else
			{
				m_ScrollPosOffset = 0f;
			}
			num = ((m_HorizontalPivotType == HorizontalPivotType.Left) ? 1 : (-1));
			if (m_HorizontalPivotType != HorizontalPivotType.Center)
			{
				float x = positionRegardlessOfPivot.x;
				Vector2 properSize3 = m_BaseTransform.GetProperSize();
				positionRegardlessOfPivot.x = x - properSize3.x * scaler.scaler.scaleFactor / 2f * (float)num;
				positionRegardlessOfPivot.x += m_ExpandedSize.x * scaler.scaler.scaleFactor / 2f * (float)num;
			}
			RectTransform component = MaterialUIScaler.GetParentScaler(m_DropdownPanel).GetComponent<RectTransform>();
			Vector3 position = component.position;
			float num2 = position.x / scaler.scaler.scaleFactor - component.rect.width / 2f;
			float num3 = positionRegardlessOfPivot.x / scaler.scaler.scaleFactor - m_ExpandedSize.x / 2f;
			if (num3 < num2 + m_MinDistanceFromEdge)
			{
				positionRegardlessOfPivot.x += (num2 + m_MinDistanceFromEdge - num3) * scaler.scaler.scaleFactor;
			}
			Vector3 position2 = component.position;
			num2 = position2.x / scaler.scaler.scaleFactor + component.rect.width / 2f;
			num3 = positionRegardlessOfPivot.x / scaler.scaler.scaleFactor + m_ExpandedSize.x / 2f;
			if (num3 > num2 - m_MinDistanceFromEdge)
			{
				positionRegardlessOfPivot.x -= (num3 - (num2 - m_MinDistanceFromEdge)) * scaler.scaler.scaleFactor;
			}
			Vector3 position3 = component.position;
			num2 = position3.y / scaler.scaler.scaleFactor + component.rect.height / 2f;
			num3 = positionRegardlessOfPivot.y / scaler.scaler.scaleFactor + m_ExpandedSize.y / 2f;
			if (num3 > num2 - m_MinDistanceFromEdge)
			{
				positionRegardlessOfPivot.y -= (num3 - (num2 - m_MinDistanceFromEdge)) * scaler.scaler.scaleFactor;
			}
			Vector3 position4 = component.position;
			num2 = position4.y / scaler.scaler.scaleFactor - component.rect.height / 2f;
			num3 = positionRegardlessOfPivot.y / scaler.scaler.scaleFactor - m_ExpandedSize.y / 2f;
			if (num3 < num2 + m_MinDistanceFromEdge)
			{
				positionRegardlessOfPivot.y += (num2 + m_MinDistanceFromEdge - num3) * scaler.scaler.scaleFactor;
			}
			return positionRegardlessOfPivot;
		}

		private DropdownListItem CreateItem(OptionData data, int index)
		{
			DropdownListItem dropdownListItem = new DropdownListItem();
			GameObject gameObject = UnityEngine.Object.Instantiate(m_ListItemTemplate.rectTransform.gameObject);
			dropdownListItem.rectTransform = gameObject.GetComponent<RectTransform>();
			dropdownListItem.rectTransform.SetParent(m_ListItemTemplate.rectTransform.parent);
			dropdownListItem.rectTransform.localScale = Vector3.one;
			dropdownListItem.rectTransform.localEulerAngles = Vector3.zero;
			dropdownListItem.rectTransform.anchoredPosition3D = Vector3.zero;
			dropdownListItem.canvasGroup = dropdownListItem.rectTransform.GetComponent<CanvasGroup>();
			dropdownListItem.text = dropdownListItem.rectTransform.GetChildByName<Text>("Text");
			if (m_OptionDataList.imageType == ImageDataType.Sprite)
			{
				dropdownListItem.image = dropdownListItem.rectTransform.GetChildByName<Image>("Icon");
				UnityEngine.Object.Destroy(dropdownListItem.rectTransform.GetChildByName<VectorImage>("Icon").gameObject);
			}
			else
			{
				dropdownListItem.image = dropdownListItem.rectTransform.GetChildByName<VectorImage>("Icon");
				UnityEngine.Object.Destroy(dropdownListItem.rectTransform.GetChildByName<Image>("Icon").gameObject);
			}
			DropdownTrigger component = gameObject.GetComponent<DropdownTrigger>();
			component.index = index;
			component.dropdown = this;
			if (!string.IsNullOrEmpty(data.text))
			{
				dropdownListItem.text.text = data.text;
			}
			else
			{
				UnityEngine.Object.Destroy(dropdownListItem.text.gameObject);
			}
			if (data.imageData != null && data.imageData.ContainsData(checkCurrentTypeOnly: true))
			{
				dropdownListItem.image.SetImage(data.imageData);
			}
			else
			{
				UnityEngine.Object.Destroy(dropdownListItem.image.gameObject);
			}
			gameObject.GetComponent<MaterialRipple>().rippleData = m_ItemRippleData.Copy();
			if (m_HighlightCurrentlySelected && index == m_CurrentlySelected)
			{
				gameObject.GetComponent<Image>().color = m_ItemRippleData.Color.WithAlpha(m_ItemRippleData.EndAlpha);
			}
			dropdownListItem.text.color = m_ItemTextColor;
			dropdownListItem.image.color = m_ItemIconColor;
			dropdownListItem.canvasGroup.alpha = 0f;
			return dropdownListItem;
		}

		private float CalculateMaxItemWidth()
		{
			TextGenerator textGenerator = new TextGenerator();
			TextGenerationSettings generationSettings = m_ListItemTemplate.text.GetGenerationSettings(new Vector2(float.MaxValue, float.MaxValue));
			float num = 0f;
			for (int i = 0; i < m_OptionDataList.options.Count; i++)
			{
				float num2 = 0f;
				if (!string.IsNullOrEmpty(m_OptionDataList.options[i].text))
				{
					num2 = textGenerator.GetPreferredWidth(m_OptionDataList.options[i].text, generationSettings) / scaler.scaler.scaleFactor;
					num2 += 16f;
				}
				if (m_OptionDataList.imageType == ImageDataType.Sprite)
				{
					if (m_OptionDataList.options[i].imageData.sprite != null)
					{
						num2 += m_ListItemTemplate.image.rectTransform.rect.width;
						num2 += 16f;
					}
				}
				else if (m_OptionDataList.options[i].imageData != null && m_OptionDataList.options[i].imageData.vectorImageData != null)
				{
					num2 += m_ListItemTemplate.image.rectTransform.rect.width;
					num2 += 16f;
				}
				num2 += 16f;
				num = Mathf.Max(num, num2);
			}
			return num;
		}
	}
}
